package pers.cz.commons.collection_server;

import pers.cz.mapper.AutoCollectMethodParamsMapper;
import pers.cz.mapper.AutoCollectTestCaseMapper;
import pers.cz.mapper.AutoCollectTestCaseSqlMapper;
import pers.cz.model.AutoCollectMethodParamsWithBLOBs;
import pers.cz.model.AutoCollectTestCaseSql;
import pers.cz.model.AutoCollectTestCaseWithBLOBs;
import pers.cz.spring.SpringContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * 同步数据到mysql
 * @program: PostGirl-panent
 * @description: InterfaceSyncToDb
 * @author: Cheng Zhi
 * @create: 2022-02-09 13:04
 **/
public class InterfaceSyncToDb {

    static Logger logger = LoggerFactory.getLogger(InterfaceSyncToDb.class);
    /**
     * 同步录制的案例到数据库
     * @param list
     */
    public static void SyncToDb(List<AutoCollectTestCaseWithBLOBs> list) {

        SpringContextUtil.getBean(AutoCollectTestCaseMapper.class).batchInsert(list);
    }

    /**
     * 同步录制的sql到数据库
     * @param list
     */
    public static void SyncSqlToDb(List<AutoCollectTestCaseSql> list) {

        SpringContextUtil.getBean(AutoCollectTestCaseSqlMapper.class).batchInsert(list);
    }

    /**
     * 同步录制的底层方法出入参到数据库
     * @param list
     */
    public static void SyncMethodParamToDb(List<AutoCollectMethodParamsWithBLOBs> list) {

        try {
            SpringContextUtil.getBean(AutoCollectMethodParamsMapper.class).batchInsert(list);
        } catch (Exception e) {
            logger.debug("插入数据库异常： " + e.getMessage());
        }
    }
}
